package com.atguigu.gulimall.auth.utils;

import java.util.Random;

/**
 * @Classname VerificationCode
 * @Description TODO
 * @Date 2021/9/13 16:23
 * @Author Anonymous
 */
public class VerificationCode {
    public static void main(String[] args) {
        String code = generateSmsCode();
        System.out.println(code);
    }
    /**
     * 生成验证码
     */
    public static String generateSmsCode() {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < SMS_LENGTH; i++) {
            sb.append(NUMBER_CHARS[new Random().nextInt(10)]);
        }
        return sb.toString();
    }

    private final static char[] NUMBER_CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    /**
     * 验证码长度
     */
    private final static int SMS_LENGTH = 6;

}
